{% extends "!page.html" %}
{#
  You can't override layout.html in RTD
  https://github.com/rtfd/readthedocs.org/issues/152
  Therefore, placing in page.html
#}

{% block extrahead %}

  {{ super() }}

  {# Helper for tracking outbound links with GA #}
  <script>
    // Read The Docs is responsible for loading GA by
    // injecting a script into all pages. The function
    // below assumes that this has happened.
    window.trackOutboundLink = function(url) {
      if (typeof(ga) == 'function') {
        ga('send', 'event', 'outbound', 'click', url, {
          'transport': 'beacon',
          'hitCallback': function(){document.location = url;}
        });
        // cancel navigation due to click, allow the hitCallback to
        // navigate to the next page after ga() has registered event
        return false;
      } else {
        console.log("trackOutboundLink: Unable to access ga()");
        // ga() was a no-go so allow navigation to proceed
        return true;
      }
    };
  </script>

  {# Verify the site for Google Webmaster Tools #}
  <meta name="google-site-verification" content="v8MtCUC2nV2dO-4CSGb5flD1MyPKJvw7wBDOYRwBadw" />

  {# fonts for cookie consent box #}
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,300;0,400;0,700;0,900;1,300;1,400;1,700;1,900&display=swap" rel="stylesheet">

  {# Last in <head> to override any canonical link that sphinx adds #}
  {% if pagename in canonical_urls %}
    <link rel="canonical" href="{{ canonical_urls[pagename] }}" />
  {% endif %}

  {# Open Graph metadata #}
  <meta property="og:image" content="https://docs.citusdata.com/en/stable/_images/citus-docs-og-logo.png" />
  <meta property="og:title" content="{{ title }} - {{ docstitle }}" />
  <meta property="og:description" content="Docs for the Citus open source extension to Postgres. Citus gives you Postgres at any scale—from a single node to a large distributed database cluster. Available as 100% open source &amp; as a managed service with Azure Cosmos DB for PostgreSQL." />
{% endblock %}

{% block header %}
  <div id="cookie-banner"></div>
{% endblock %}

{% block sidebartitle %}
  <!--<a class="skiplink" href="#maincontent">Skip to main content ></a> -->
  <a class="skiplink" href="#maincontent">跳转到正文 ></a>
  <!-- <a href="https://citusdata.com" class="homepage"> -->
  <a href="/" class="homepage">  
    <img src={{ pathto('_images/logo.png', 1) }} class="logo" alt="Citus Data logo" />
  </a>

  {{ super() }}
{% endblock %}

{% block body %}
  <div id="maincontent" />

  {{ super() }}

{% endblock %}

{% block footer %}
  {{ super() }}

  <script>
    var cookieBanner = document.createElement('div');
    cookieBanner.id = 'cookie-banner';
    document.body.prepend(cookieBanner);
  </script>

  {# msft standard cookie script #}
  <script src='https://wcpstatic.microsoft.com/mscc/lib/v2/wcp-consent.js'></script>

  {# cookie consent script #}
  <script type="text/javascript">
    function loadHeap() {
      window.heap=window.heap||[],heap.load=function(e,t){window.heap.appid=e,window.heap.config=t=t||{};var r=t.forceSSL||"https:"===document.location.protocol,a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=(r?"https:":"http:")+"//cdn.heapanalytics.com/js/heap-"+e+".js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(a,n);for(var o=function(e){return function(){heap.push([e].concat(Array.prototype.slice.call(arguments,0)))}},p=["addEventProperties","addUserProperties","clearEventProperties","identify","removeEventProperty","setEventProperties","track","unsetEventProperty"],c=0;c<p.length;c++)heap[p[c]]=o(p[c])};
      heap.load("4002524638");
      console.log("loading tracking scripts");
    }
    function onConsentChanged(categoryPreferences) {
      ga('send', 'event', 'cookie consent', 'changed', window.location.href + "(" + categoryPreferences + ")");
      console.log("onConsentChanged", categoryPreferences);
      if (categoryPreferences.Analytics) {
        loadHeap();
      }
    }
    function manageConsent() {
      if(siteConsent.isConsentRequired){
        siteConsent.manageConsent();
      }
    }
    window.WcpConsent && WcpConsent.init("en-US", "cookie-banner", function (err, _siteConsent) {
      if (!err) {
        siteConsent = _siteConsent;
        console.log(siteConsent);
        if (_siteConsent.isConsentRequired == false) {
          loadHeap();
          var mngLink = document.createElement('span'),
              userConsent = siteConsent.getConsent();
          mngLink.innerHTML = '<a href="https://privacy.microsoft.com/privacystatement" target="_blank" rel="noopener">Privacy Statement</a><br><br>';
          /* document.querySelector("footer div[role=contentinfo]").prepend(mngLink); */
        }
        else {
          var mngLink = document.createElement('span'),
              userConsent = siteConsent.getConsent();
          mngLink.innerHTML = '<a href="https://privacy.microsoft.com/privacystatement" target="_blank" rel="noopener">Privacy</a> | <a href="javascript:void(0)" id="mng-cookies">Manage Cookies</a><br><br>';
          /* document.querySelector("footer div[role=contentinfo]").prepend(mngLink); */
          if (userConsent.Analytics == true) {
            loadHeap();
          }
          var clickMng = document.querySelector('#mng-cookies');
          clickMng.addEventListener('click', function (event) {
          	manageConsent();
          });
        }
      } else {
        console.log("Error initializing WcpConsent: "+ err);
      }
    }, onConsentChanged, WcpConsent.themes.dark);
    window.consentCheckRequired = true;
  </script>
{% endblock %}
